<?php
/**
 * Created by PhpStorm.
 * User: sunku
 * Date: 2018/1/16
 * Time: 16:16
 */

namespace Admin\Logic;
use Think\Model;

class MsgLogic extends Model
{
    protected $trueTableName = 'wz_message';

    /**
     * @param $params
     * @return array
     */
    public function getSystemMsg($params) {
        $uid = intval($params['uid']);
        //用户组
        $userGroup = D('Resource/User','Service')->getUserRelationGroupInfo(['au.id'=>$uid]);
        $group_id = $userGroup['id'];
        $data = [];
        $data['uid'] = $uid;
        $data['status'] = 0;
        $data['_string'] = "type = 0";
        if($group_id==3){
            $data['_string'] = "type = 0 OR type = 9";
        }elseif($group_id==4){
            $data['uid'] = 0;
            $data['_string'] = "type = 0 OR type = 1";
        }elseif($group_id==5){
            $data['uid'] = 0;
            $data['_string'] = "type = 0 OR type = 3";
        }elseif($group_id==6){
            $data['uid'] = 0;
            $data['_string'] = "type = 0 OR type = 5";
        }elseif($group_id==2){
            $data['uid'] = 0;
            $data['_string'] = "type = 0 OR type = 7";
        }

        $total = D('Resource/Message','Service')->getMessageCount($data);

        $msgList = D('Resource/Message','Service')->getAllMessageList($data);

        return ['msgList'=>$msgList, 'total'=>$total];
    }
    /**
     * @param $params
     * @return mixed
     */
    public function searchMsgList($params) {
        $uid = intval($params['uid']);
        $page = $params['page'];
        $page_size = $params['page_size'];
        //用户组
        $userGroup = D('Resource/User','Service')->getUserRelationGroupInfo(['au.id'=>$uid]);
        $group_id = $userGroup['id'];
        $data = [];
        $data['uid'] = $uid;
        $data['page'] = $page;
        $data['page_size'] = $page_size;
        $data['status'] = ['in',[0,1]];
        $data['_string'] = "type = 0";
        if($group_id==3){
            $data['_string'] = "type = 0 OR type = 9";
        }elseif($group_id==4){
            $data['uid'] = 0;
            $data['_string'] = "type = 0 OR type = 1";
        }elseif($group_id==5){
            $data['uid'] = 0;
            $data['_string'] = "type = 0 OR type = 3";
        }elseif($group_id==6){
            $data['uid'] = 0;
            $data['_string'] = "type = 0 OR type = 5";
        }elseif($group_id==2){
            $data['uid'] = 0;
            $data['_string'] = "type = 0 OR type = 7";
        }

        $result = D('Resource/Message', 'Service')->searchMessageList($data);
        return $result;
    }
}